package com.inspection.controller.sys;

import com.inspection.entity.SysDictDO;
import com.inspection.model.dto.SysDictDTO;
import com.inspection.model.dto.SysDictQueryDTO;
import com.inspection.model.vo.SysDictQueryVO;
import com.inspection.service.SysDictService;
import com.inspection.support.Wrapper;
import com.inspection.support.anno.SysLogAnno;
import com.inspection.support.model.ItemList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author zhaoqi
 * @since 2020-12-14
 */
@RestController
public class SysDictController {

    @Autowired
    private SysDictService sysDictService;

    @SysLogAnno(operateCode =100201,operateName = "系统字典：新增")
    @RequestMapping("/sys/dict/save")
    public Wrapper<String> saveDict(@RequestBody SysDictDTO save) {
        sysDictService.saveDict(save);
        return Wrapper.ok("ok");
    }
    @RequestMapping("/sys/dict/get")
    public Wrapper<SysDictDO> getDict(@RequestBody SysDictDTO get) {
        return Wrapper.ok(sysDictService.getDict(get));
    }



    @SysLogAnno(operateCode =100202,operateName = "系统字典：更新")
    @RequestMapping("/sys/dict/update")
    public Wrapper<String> updateDict(@RequestBody SysDictDTO update) {
        sysDictService.updateDict(update);
        return Wrapper.ok("ok");
    }

    //目录
    @RequestMapping("/sys/dict/catalogue")
    public Wrapper<ItemList<SysDictDO>> queryDictCatalogue(@RequestBody SysDictQueryDTO query) {
        return Wrapper.ok(ItemList.buildItems(sysDictService.queryDictCatalogue(query)));
    }
    //分页获取字典
    @RequestMapping("/sys/dict/page")
    public Wrapper<Page<SysDictDO>> pageDict(@RequestBody SysDictQueryDTO query) {
        return Wrapper.ok(sysDictService.pageDict(query));
    }

    //分页获取字典
    @RequestMapping("/sys/dict/query")
    public Wrapper<SysDictQueryVO> queryDict(@RequestBody SysDictQueryDTO query) {
        return Wrapper.ok(sysDictService.queryDict(query));
    }


    @SysLogAnno(operateCode =100203,operateName = "系统字典：删除")
    @RequestMapping("/sys/dict/del")
    public Wrapper<String> delDict(@RequestBody SysDictDTO del) {
        sysDictService.delDict(del);
        return Wrapper.ok("ok");
    }

    @SysLogAnno(operateCode =100204,operateName = "系统字典：批量删除")
    @RequestMapping("/sys/dict/batchDel")
    public Wrapper<String> batchDict(@RequestBody SysDictDTO del) {
        sysDictService.batchDelDict(del);
        return Wrapper.ok("ok");
    }




}
